<?php
namespace app\models;

use yii\base\Model;
use yii\web\UploadedFile;

class UploadForm extends Model
{
    /**
     * @var UploadedFile
     */
    public $imageFile;
    public $name;
    public $stock;
    public $status;
    public $price;
    public function rules()
    {
        return [
            [['path '], 'file', 'skipOnEmpty' => false],
             [['stock'], 'integer'],
              [['price'], 'number'],
            [['name'], 'string', 'max' => 20,'min'=>5],
            [['path'], 'string', 'max' => 100],
            [['status'], 'string', 'max' => 5],
        ];
    }
    
    public function upload()
    {
        if ($this->validate()) {
            $this->path ->saveAs('uploads/' . $this->path ->baseName . '.' . $this->path ->extension);
            $arr=['code'=>'0',"data"=>'uploads/' . $this->path ->baseName . '.' . $this->path ->extension];
            return $arr;
        } else {
            return ['code'=>'1',"data"=>''];
        }
    }
}

?>